#include "App.h"

static QString TCP_SERVER_ADDR = "127.0.0.1";
static int     TCP_SERVER_PORT = 4090;
App::App(QObject* parent) : ChatClient(parent) {
    thread = new QThread();

    tcpClient = new TcpClient();
    tcpClient->moveToThread(thread);
    thread->start();

    tcpClient->ClientConnectToHost(TCP_SERVER_ADDR, TCP_SERVER_PORT);

    connect(tcpClient, &TcpClient::signalPacket, this, &App::onPacket);
    connect(this, &App::signalLogin, this, &App::onLogin);
}
App::~App() {}

void App::send(packge::Packge& pack) {
    tcpClient->send(pack);
}

void App::onPacket(std::shared_ptr<packge::Packge> pack) {
    processPacket(*pack);
}

void App::onLogin(data::UserInfo userInfo, int code, QString message) {
    qDebug() << code << ":" << message;
}